package com.example.spark.controller;

import com.example.spark.entity.Cooperator;
import com.example.spark.entity.result.CommonResult;
import com.example.spark.service.CooperatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
@CrossOrigin
@RestController
@RequestMapping("/cooperator")
public class CooperatorController {

    @Autowired
    private CooperatorService cooperatorService;

    //根据id查询合作单位
    @GetMapping("selectCooperator/{id}")
    public CommonResult selectCooperator(@PathVariable Long id) {

        return cooperatorService.selectCooperator(id);
    }

    //添加合作单位
    @PostMapping("addCooperator")
    public CommonResult addCooperator(@RequestBody Cooperator cooperator) {

        return cooperatorService.addCooperator(cooperator);
    }

    //删除合作单位
    @DeleteMapping("deleteCooperator/{id}")
    public CommonResult deleteCooperator(@PathVariable Long id) {

        return cooperatorService.deleteCooperator(id);
    }

    //修改合作单位
    @PutMapping("updateCooperator")
    public CommonResult updateCooperator(@RequestBody Cooperator cooperator) {

        return cooperatorService.updateCooperator(cooperator);
    }

    //图片
    @PutMapping("cooperatorPhotos")
    public  CommonResult addPhoto(@RequestParam MultipartFile photoFile, @RequestParam Long id) throws IOException {

        return cooperatorService.addPhoto(photoFile,id);
    }
}
